from django.shortcuts import render
from django.views.static import serve
from rest_framework import viewsets, permissions
from case.models import RunResult
from case.serializers import RunResultSerializer

class RunResultViewSet(viewsets.mixins.ListModelMixin, viewsets.GenericViewSet):
    queryset = RunResult.objects.all()
    serializer_class = RunResultSerializer
    permission_classes = [permissions.IsAuthenticated,] # 判断是否登录

# class RunResultViewSet(viewsets.ReadOnlyModelViewSet):
#     queryset = RunResult.objects.all()
#     serializer_class = RunResultSerializer


def static_serve(request, path, document_root=None, show_indexes=False):
    resp = serve(request, path, document_root, show_indexes)

    if resp.status_code == 200:
        if path.endswith(".yaml") or path.endswith(".log"):
            resp.headers["Content-Type"] = "text/css;charset=utf-8"

    return resp


